package com.chw.springbootmybatis.controller;

import com.chw.springbootmybatis.dao.UserMapper;
import com.chw.springbootmybatis.entity.Role;
import com.chw.springbootmybatis.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * @author 车宏伟
 * @date 2020/10/2 18:02
 */
@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    UserMapper userMapper;

    @GetMapping("getUser")
//    @Transactional
    public String getUser(Long id) {
//        User user = new User();
//        user.setId(id);
//        user.setCreateUser(1L);
//        user.setCreateTime(LocalDateTime.now());
//        Role role = new Role();
//        role.setId(666L);
//
//        User byUser = userMapper.findByUser(user);
//        User byUser = userMapper.findById(id);

//        User userRole = userMapper.findUserRole(); // 手动映射 自动映射
//        System.out.println(userRole);


        User user = userMapper.selectUserRole(1L); // 嵌套查询
//        user.setRole(new Role());
//        Role role = user.getRole();
//        System.out.println(role.toString());
//        System.out.println(user.toString());


//        System.out.println(byId);
//        User byId1 = userMapper.findById(id);
//        System.out.println(byId1);


        return user.toString();
    }


}
